﻿@model Zor_Web.Models.Base.V_Zor_Hous
@using Webdiyer.WebControls.Mvc;

@{
    Layout = null;
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>房屋信息列表</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/Styles/zor.css" rel="stylesheet" />
    <!-- 框架必要 -->
    <script src="~/Content/Scripts/jquery/jquery-1.9.1.min.js"></script>
    <script src="~/Content/Scripts/learunui-framework.js"></script>
    <script src="~/Content/Scripts/Zor_AJax.js"></script>
    <!-- 消息提示 -->
    <script language='javascript' src='~/Content/layer/layer.js'></script>
    <!-- 日期选择器 -->
    <script src="~/Content/laydate/laydate.js"></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script>
</head>
<body class="gray-bg">
    <div class="layui-tab layui-tab-brief main-tab-container ">
        <div class="col-sm-12 ct-padding">
            <div class="col-sm-9 ct-padding">
                <button id="btnAdd" class="layui-btn layui-btn layui-btn-small"><span class="glyphicon glyphicon-plus"></span> 新增</button>
                <button id="btnUpdate" class="layui-btn layui-btn-warm layui-btn-small"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>
                <button id="btnDelete" class="layui-btn layui-btn-danger layui-btn-small"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                <button id="btnSearch" class="layui-btn layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <button id="btnRent" class="layui-btn layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-jpy"></span> 租赁</button>              
                <button id="btnMessage" class="layui-btn layui-btn-orchid layui-btn-small"><span class="glyphicon glyphicon-list-alt"></span> 详情</button>
                <button id="btnExport" class="layui-btn layui-btn-springgreen  layui-btn-small"><span class="glyphicon glyphicon-share"></span> 导出</button>
                <button id="btnReplace" class="layui-btn layui-btn-blue layui-btn-small"><span class="glyphicon glyphicon-refresh"></span> 刷新</button>
            </div>
        </div>
        <div class="layui-tab-content" style="overflow-x:scroll;white-space:nowrap;">
            <table class="layui-table" lay-skin="line">
                <thead>
                    <tr>
                        <th hidden></th>
                        <th></th>
                        <th>所属楼宇</th>
                        <th>所属单元</th>
                        <th>房号</th>
                        <th>所在楼层</th>
                        <th>业主姓名</th>
                        <th>身份证号</th>
                        <th>联系电话</th>
                        <th>业主性别</th>
                        <th>房屋面积(㎡)</th>
                        <th hidden>房屋性质</th>
                        <th>房屋属性</th>
                        <th>房屋用途</th>
                        <th>第几户</th>
                        <th>产权</th>
                    </tr>
                </thead>
                <tbody id="accordion">
                    @foreach (var item in Model.PageData)
                    {
                        if (@item.Nature == null)
                        {

                            <tr >
                                <td hidden>@item.Hs_Id</td>
                                <td><input type="radio" name="chk" id="@item.Hs_Id" value="@item.Hs_Id" /></td>
                                <td> <span  class='label label-warning pull-center'>请将（@item.Bd_Name）信息补充完整</span></td> 
                                <td>@item.Uim_Name</td>
                                <td>@item.Hs_Number</td>
                                <td>@item.Hs_InFloor</td>
                                <td>@item.NatPer_Name</td>
                                <td>@item.NatPer_IDNumber</td>
                                <td>@item.NatPer_Phone</td>
                                <td>@item.NatSex</td>
                                <td>@item.Hs_Proportion</td>
                                <td hidden>@item.Nature</td>
                                <td>@item.Attribute</td>
                                <td>@item.HousUse</td>
                                <td>@item.Hs_household</td>
                                <td>@item.Cqsx</td>
                                <td hidden>@item.Hs_Nature</td>
                                <td hidden>@item.Hs_attribute</td>
                                <td hidden>@item.Hs_HousUse</td>
                                <td hidden>@item.Hs_Cqsx</td>
                                <td hidden>@item.Uf_Id</td>
                                <td hidden>@item.Bd_Id</td>
                                <td hidden>@item.NatPer_Sex</td>
                            </tr>
                        }
                        else
                        {


                            <tr>
                                <td hidden>@item.Hs_Id</td>
                                <td><input type="radio" name="chk" id="@item.Hs_Id" value="@item.Hs_Id" /></td>
                                <td>@item.Bd_Name</td>
                                <td>@item.Uim_Name</td>
                                <td>@item.Hs_Number</td>
                                <td>@item.Hs_InFloor</td>
                                <td>@item.NatPer_Name</td>
                                <td>@item.NatPer_IDNumber</td>
                                <td>@item.NatPer_Phone</td>
                                <td>@item.NatSex</td>
                                <td>@item.Hs_Proportion</td>
                                <td hidden>@item.Nature</td>
                                <td>@item.Attribute</td>
                                <td>@item.HousUse</td>
                                <td>@item.Hs_household</td>
                                <td>@item.Cqsx</td>
                                <td hidden>@item.Hs_Nature</td>
                                <td hidden>@item.Hs_attribute</td>
                                <td hidden>@item.Hs_HousUse</td>
                                <td hidden>@item.Hs_Cqsx</td>
                                <td hidden>@item.Uf_Id</td>
                                <td hidden>@item.Bd_Id</td>
                                <td hidden>@item.NatPer_Sex</td>
                                <td hidden>@item.NatPer_Id</td>
                            </tr>
                        }
                    }

                </tbody>
            </table>
        </div>
        <div class="col-sm-12">
            <div class="col-sm-10">
                @Html.Pager(Model.PageData, new PagerOptions { PageIndexParameterName = "index", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "bootstrappager", @class = "pagination" })
            </div>
            <div class="col-sm-2 to-righjt">
                共 @Model.PageData.TotalItemCount 条记录，页 @Model.PageData.CurrentPageIndex/@Model.PageData.TotalPageCount
            </div>
        </div>
    </div>
    <!-- 模态 -->
    <div id="myModal" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
            <form class="form-horizontal m-t">
                <div class="layui-form-item" hidden>
                    <label class="col-sm-3 layui-form-label">ID：</label>
                    <div class="col-sm-9">
                        <input id="Hs_Id" type="text" class="form-control">
                    </div>
                </div>
                <div class="layui-form-item" hidden>
                    <label class="col-sm-2 layui-form-label">NatPer_Id：</label>
                    <div class="col-sm-4">
                        <input id="NatPer_Id" type="text" class="form-control">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">所属楼宇：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Bd_Id"></select>
                    </div>
                    <label class="col-sm-2 layui-form-label">所属单元：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Uf_Id"></select>
                    </div>
                </div>
             
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房号：</label>
                    <div class="col-sm-4">
                        <input id="Hs_Number" name="Hs_Number" type="text" class="form-control" autofocus="autofocus" datacol="yes" err="房号" checkexpession="NotNull">
                    </div>
                    <label class="col-sm-2 layui-form-label">所在楼层：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Hs_InFloor"></select>                        
                    </div>
                </div>
             
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">业主姓名：</label>
                    <div class="col-sm-4">
                        <input id="NatPer_Name" type="text" class="form-control" placeholder="..." autofocus="autofocus" autofocus="autofocus" datacol="yes" err="业主姓名" checkexpession="ChineseStr">
                    </div>
                    <label class="col-sm-2 layui-form-label">身份证号：</label>
                    <div class="col-sm-4">
                        <input id="NatPer_IDNumber" type="text" class="form-control" placeholder="..." autofocus="autofocus" datacol="yes" err="业主身份证号" checkexpession="IDCardOrNull">
                    </div>
                </div>
             
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">联系电话：</label>
                    <div class="col-sm-4">
                        <input id="NatPer_Phone" type="text" class="form-control" placeholder="..." autofocus="autofocus" datacol="yes" err="业主联系电话" checkexpession="MobileOrPhoneOrNull">
                    </div>
                    <label class="col-sm-2 layui-form-label">业主性别：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="NatPer_Sex">
                            <option value="1">男</option>
                            <option value="2">女</option>
                        </select>
                    </div>
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房屋面积(㎡)：</label>
                    <div class="col-sm-4">
                        <input id="Hs_Proportion" type="text" class="form-control" datacol="yes" err="房屋面积" checkexpession="Double">
                    </div>
                    <label class="col-sm-2 layui-form-label">第几户：</label>
                    <div class="col-sm-4">
                        <input id="Hs_household" type="text" class="form-control" datacol="yes" err="第几户" checkexpession="Num">
                    </div>
                    
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房屋属性：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Hs_attribute">                                               
                            <option value="1">住宅</option>
                            <option value="2">非住宅</option>
                        </select>
                    </div>
                    <label class="col-sm-2 layui-form-label">房屋用途：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Hs_HousUse">
                            <option value="0">无</option>
                            <option value="1">闲置空房</option>
                            <option value="2">自住</option>
                            <option value="3">租赁</option>


                        </select>
                    </div>
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房屋产权：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Hs_Cqsx" disabled="">
                            <option value="1">个人</option>
                            <option value="2">非个人</option>
                        </select>
                    </div>
                    <label class="col-sm-2 layui-form-label" hidden>房屋性质：</label>
                    <div class="col-sm-4" hidden>
                        <select name="temp" class="form-control" id="Hs_Nature">
                            <option value="0">无</option>
                            <option value="1">民宅</option>
                            <option value="2">商用</option>
                            <option value="3">商住两用</option>

                        </select>
                    </div>
                </div>
            
             
            </form>
        </div>
        <div class="box-footer">          
            <button id="btnSure" class="btn btn-info pull-right">
                <i class="fa fa-check"></i>提交
            </button>
        </div>
    </div>

    <!-- 详情模态 -->
    <div id="myModalMessage" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
            <form class="form-horizontal m-t">
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房号：</label>
                    <div class="col-sm-4 layui-input" id="Hs_Number1"></div>
                    <label class="col-sm-2 layui-form-label">所在单元：</label>
                    <div class="col-sm-4 layui-input" id="Uim_Name"></div>
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">所在楼层：</label>
                    <div class="col-sm-4 layui-input" id="Hs_InFloor1"></div>
                    <label class="col-sm-2 layui-form-label">业主姓名：</label>
                    <div class="col-sm-4 layui-input" id="NatPer_Name1"></div>
                </div>
             
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">身份证号：</label>
                    <div class="col-sm-4 layui-input" id="NatPer_IDNumber1"></div>
                    <label class="col-sm-2 layui-form-label">联系电话：</label>
                    <div class="col-sm-4 layui-input" id="NatPer_Phone1"></div>
                </div>
            
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">业主性别：</label>
                    <div class="col-sm-4 layui-input" id="NatSex"></div>
                    <label class="col-sm-2 layui-form-label">房屋面积(㎡)：</label>
                    <div class="col-sm-4 layui-input" id="Hs_Proportion1"></div>
                </div>
             
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label" hidden>房屋性质：</label>
                    <div class="col-sm-4 layui-input" id="Nature" hidden></div>
                    <label class="col-sm-2 layui-form-label">产权：</label>
                    <div class="col-sm-4 layui-input" id="Cqsx"></div>
                    <label class="col-sm-2 layui-form-label" >房屋属性：</label>
                    <div class="col-sm-4 layui-input" id="Attribute" ></div>
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房屋用途：</label>
                    <div class="col-sm-4 layui-input" id="HousUse"></div>
                    <label class="col-sm-2 layui-form-label">第几户：</label>
                    <div class="col-sm-4 layui-input" id="Hs_household1"></div>
                </div>            
            </form>
        </div>
    </div>

    <!-- 租赁模态 -->
    <div id="myModalLease" hidden data-backdrop="static">
        <div id="divLeasefrom" class="layui-tab-content">
            <form class="form-horizontal m-t">
                <div class="layui-form-item" hidden>
                    <label class="col-sm-3 layui-form-label">ID：</label>
                    <div class="col-sm-9">
                        <input id="HouseShopId" type="text" class="form-control">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房号：</label>
                    <div class="col-sm-4">
                        <input readonly id="Hs_Num" type="text" class="form-control">
                    </div>
                    <label class="col-sm-2 layui-form-label">租户：</label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Tenant_Id"></select>
                    </div>
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">租赁开始日期：</label>
                    <div class="col-sm-4">
                        <input id="Lease_StartTime" class="laydate-icon form-control layer-date"></div>
                    <label class="col-sm-2 layui-form-label">租赁结束日期：</label>
                    <div class="col-sm-4">
                        <input id="Lease_EndTime" class="laydate-icon form-control layer-date">
                    </div>
                </div>
              
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">租金：</label>
                    <div class="col-sm-4">
                        <input id="Lease_Rent" type="text" class="form-control" autofocus="autofocus">
                    </div>
                    <label class="col-sm-2 layui-form-label">备注：</label>
                    <div class="col-sm-4">
                        <input id="Lease_Remarks" type="text" class="form-control" autofocus="autofocus">
                    </div>
                </div>
              
            </form>
        </div>     
        <div class="box-footer">           
            <button id="btnRentSure" class="btn btn-info pull-right">
                <i class="fa fa-check"></i>提交
            </button>            
        </div>
    </div>
    @using (Html.BeginForm("Zor_Housing", "Base", new RouteValueDictionary { { "Model", Model } }, FormMethod.Get))
    {
    <!-- 查询模态框 -->
        <div id="myModalSearch" hidden data-backdrop="static">
            <div id="divselectfrom" class="layui-tab-content">
                <form class="form-horizontal m-t">
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">房号：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="Hs_Number" value="@Model.Hs_Number">
                        </div>
                        <label class="col-sm-2 layui-form-label">业主姓名：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="NatPer_Name" value="@Model.NatPer_Name">
                        </div>
                    </div>
                   
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">业主身份证：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="NatPer_IDNumber" value="@Model.NatPer_IDNumber">
                        </div>
                        <label class="col-sm-2 layui-form-label">业主电话：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="NatPer_Phone" value="@Model.NatPer_Phone">
                        </div>
                    </div>
                    <div class="layui-form-item">
                       
                        <label class="col-sm-2 layui-form-label">业主性别：</label>
                        <div class="col-sm-4">
                            <select name="NatSex" class="form-control">
                                <option value="@Model.NatSex"></option>
                                <option value="@Model.NatSex">男</option>
                                <option value="@Model.NatSex">女</option>
                            </select>
                        </div>
                        <label class="col-sm-2 layui-form-label">房屋用途：</label>
                        <div class="col-sm-4">
                            <select name="HousUse" class="form-control">
                                <option value="@Model.HousUse"></option>
                                <option value="@Model.HousUse">租赁</option>
                                <option value="@Model.HousUse">自住</option>
                                <option value="@Model.HousUse">闲置空房</option>
                            </select>
                        </div>
                    </div>
                  
                
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">房屋属性：</label>
                        <div class="col-sm-4">
                            <select name="Attribute" class="form-control">
                                <option value="@Model.Attribute"></option>
                                <option value="@Model.Attribute">住宅</option>
                                <option value="@Model.Attribute">非住宅</option>
                            </select>
                        </div>
                        <label class="col-sm-2 layui-form-label" hidden>房屋性质：</label>
                        <div class="col-sm-4" hidden>
                            <select name="Nature" class="form-control">
                                <option value="@Model.Nature"></option>
                                <option value="@Model.Nature">商用</option>
                                <option value="@Model.Nature">民宅</option>
                                <option value="@Model.Nature">商住两用</option>
                            </select>
                        </div>
                    </div>
                 
                    <div class="layui-form-item" hidden>
                        <label class="col-sm-2 layui-form-label">产权：</label>
                        <div class="col-sm-4">
                            <select name="Cqsx" class="form-control">
                                <option value="@Model.Cqsx"></option>
                                <option value="@Model.Cqsx">个人</option>
                                <option value="@Model.Cqsx" hidden>非个人</option>
                            </select>
                        </div>
                    </div>
                </form>
                <div class="box-footer">
                    <button type="submit" class="btn btn-info pull-right">
                        <i class="fa fa-search"></i>查询
                    </button>
                </div>
            </div>
        </div>
    }

    <!-- 导出模态 -->
    <form action="/Base/ExportHousing" enctype="multipart/form-data" method="post" id="formDownload">
        <div id="exportHtml" style="display:none;">
            <div class="eh_wrap">
                <div class="eh_head">
                    <p style="">请选择您要导出的数据列</p>
                </div>
                <table width="100%" cellpadding="5" cellspacing="0">
                    <tr>
                        <td><input id="Bd_Name" type="checkbox" value="所属楼宇" name="chk_list" checked="checked" /><label>所属楼宇</label></td>
                        <td><input id="Uim_Name" type="checkbox" value="所属单元" name="chk_list" checked="checked" /><label>所属单元</label></td>
                        <td><input id="Hs_Number" type="checkbox" value="房号" name="chk_list" checked="checked" /><label>房号</label></td>
                        <td><input id="Hs_InFloor" type="checkbox" value="所在楼层" name="chk_list" checked="checked" /><label>所在楼层</label></td>
                    </tr>
                    <tr>
                        <td><input id="NatPer_Name" type="checkbox" value="业主名称" name="chk_list" checked="checked" /><label>业主名称</label></td>
                        <td><input id="NatPer_IDNumber" type="checkbox" value="业主身份证号" name="chk_list" checked="checked" /><label>业主身份证号</label></td>
                        <td><input id="NatPer_Phone" type="checkbox" value="业主电话" name="chk_list" checked="checked" /><label>业主电话</label></td>
                        <td><input id="NatSex" type="checkbox" value="业主性别" name="chk_list" checked="checked" /><label>业主性别</label></td>
                    </tr>
                    <tr>
                        <td><input id="Hs_Proportion" type="checkbox" value="房屋面积" name="chk_list" checked="checked" /><label>房屋面积</label></td>
                        <td><input id="Nature" type="checkbox" value="房屋性质" name="chk_list" checked="checked" /><label>房屋性质</label></td>
                        <td><input id="Attribute" type="checkbox" value="房屋属性" name="chk_list" checked="checked" /><label>房屋属性</label></td>
                        <td><input id="HousUse" type="checkbox" value="房屋用途" name="chk_list" checked="checked" /><label>房屋用途</label></td>
                    </tr>
                    <tr>
                        <td><input id="Hs_household" type="checkbox" value="本层第几户" name="chk_list" checked="checked" /><label>本层第几户</label></td>
                        <td><input id="Cqsx" type="checkbox" value="产权" name="chk_list" checked="checked" /><label>产权</label></td>
                    </tr>
                </table>
                <div class="box-footer">
                    <button type="submit" id="btnExportSure" class="btn btn-info pull-right">
                        <i class="fa fa-repeat"></i>导出
                    </button>
                    <input type="hidden" id="HousingMeg" name="HousingMeg" value="" />
                    <input type="hidden" id="where" name="where" value="" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>
<script>


    /**
  *   日期选择器
  */
    laydate.skin('molv');         //日历皮肤
    var start = {                   //开始时间选择
        elem: "#Lease_StartTime",
        format: "YYYY/MM/DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) {
            end.min = datas;
            end.start = datas
        }
    };
    var end = {                     //结束时间选择
        elem: "#Lease_EndTime",
        format: "YYYY/MM/DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) { start.max = datas }
    };
    laydate(start);
    laydate(end);


    /**
       * 获取所属楼宇
       */
    function SelectBuildingName() {

        var html = "";
        getAjax("/Base/SelectBuildingName", "", function (data) {         
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Bd_Id + "' >" + accordionJson[i].Bd_Name + "</option>";//初始化街道
            });
        });
        $("#Bd_Id").empty().append(html);
        GetUimName($("#Bd_Id").val());//初始化
        GetBdGround($("#Bd_Id").val());//初始化
        /*注册街道下拉框事件 */
        $('#Bd_Id').change(function () {
            GetUimName($(this).val());
            GetBdGround($(this).val());
        });
    }

    /**
     * 获取所属单元
     */
    function GetUimName(sid) {
        $("#Uf_Id").empty();
        var html = "";
        getAjax("/Base/GetUimName", { "id": sid }, function (data) {
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Uim_Id + "' >" + accordionJson[i].Uim_Name + "</option>";

            });
        });
        $("#Uf_Id").empty().append(html);

    }

    /**
     * 获取所有楼层
     */
    function GetBdGround(sid) {
        $("#Hs_InFloor").empty();
        var html = "";
        getAjax("/Base/GetBdGround", { "id": sid }, function (data) {
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            if (accordionJson.length > 0)
            {
                for (var i = 1; i <= accordionJson[0].Bd_Ground; i++) {
                    html += "<option value='" + i + "' >" + "第" + i + "层</option>";
                }
            }            
        });
        $("#Hs_InFloor").empty().append(html);
    }

    /**
   * 查询所有租户
   */
    function GetTenant() {
        var html = "";
        getAjax("/Base/GetTenant", "", function (data) {
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Tenant_Id + "' >" + accordionJson[i].Tenant_Name + "</option>";
            });
        });
        $("#Tenant_Id").empty().append(html);
    }

    //租赁按钮
    $(function () {
        $("#btnRent").click(function () {

            var checkId = CheckboxValueIDs();
            var Hs_Number = getTableCell(4);    //获取选中行的房屋Id
            if (checkId.length == 0) {
                layer.msg("请选择要租赁的房屋！");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一套房屋进行租赁！");
                return;
            }
            GetTenant();
            $("#HouseShopId").val(checkId[0]);
            $("#Hs_Num").val(Hs_Number);
            LayerOpen('800px', '290px', '房屋租赁', $('#myModalLease'));
        })
    })


    /**
    * 保存租赁信息
    */
    $(function () {
        $("#btnRentSure").click(function () {
            var value = $('#Tenant_Id').val();
            if (value == '0') {
                layer.msg("请选择租户！");
                return;

            }

            var txt = getTableCell(18);
            if (txt != 3) {
                layer.msg("该房屋用途不为租赁，不能产生租赁关系！");
                return;
            }
            if ($("#Lease_Rent").val() == "") {
                layer.msg("请输入租金！");
                return;
            }
            if ($("#Lease_StartTime").val() == "") {
                layer.msg("租赁开始日期不能为空！");
                return;
            }
            if ($("#Lease_EndTime").val() == "") {
                layer.msg("租赁结束日期不能为空！");
                return;
            }
            if ($("#Lease_Rent").val() != "") {
                if (!$("#Lease_Rent").val().match(/^[0-9]+([.]{1}[0-9]+){0,1}$/)) {
                    layer.msg("请输入正确的租金!");
                    return;
                }

            }
            var JsData = GetWebControls(divLeasefrom);
            var Lease_StartTime = $("#Lease_StartTime").val();
            var Lease_EndTime = $("#Lease_EndTime").val();
            ZorPostSimpleData("/Base/AddHsLease", JSON.stringify({ "lease": JsData, "startTime": Lease_StartTime, "endTime": Lease_EndTime }), function (data) {
                layer.msg(data.AnswerMeg, function () {
                    layer.closeAll();
                    Replace();
                });
            });
        })
    })

    /**
    * 增加房屋
    */
    $(function () {
        $("#btnAdd").click(function () {
            ClearWebControls(divfrom);
            SelectBuildingName();
            LayerOpen('800px', '450px', '房屋新增', $('#myModal'));
        })
    })

    /**
    * 查询房屋
    */
    $(function () {
        $("#btnSearch").click(function () {
            ClearWebControls(divfrom);
            LayerOpen('750px', '300px', '房屋查询', $('#myModalSearch'));
        })
    })
    /**
    * 修改房屋
    */
    $(function () {
        $("#btnUpdate").click(function () {

            var checkId = CheckboxValueIDs();
            var Bd_Id = getTableCell(21);
            var Hs_Number = getTableCell(4);    //获取选中行的房号
            var Uf_Id = getTableCell(20);    //获取选中行的单元ID
            var Hs_InFloor = getTableCell(5);    //获取选中行的地上层数
            var NatPer_Name = getTableCell(6);    //获取选中行的业主姓名
            var NatPer_IDNumber = getTableCell(7);    //获取选中行的业主身份证号
            var NatPer_Phone = getTableCell(8);    //获取选中行的业主电话
            var NatPer_Sex = getTableCell(22);    //获取选中行的业主性别
            var Hs_Proportion = getTableCell(10);    //获取选中行的房屋面积
            var Hs_Nature = getTableCell(16);    //获取选中行的房屋性质
            var Hs_attribute = getTableCell(17);    //获取选中行的房屋属性
            var Hs_HousUse = getTableCell(18);    //获取选中行的房屋用途
            var Hs_household = getTableCell(14);    //获取选中行的本层第几户
            var Hs_Cqsx = getTableCell(19);         //获取选中行的产权属性
            var NatPer_Id = getTableCell(22);
            $("#lbltitle").text("修改房屋");
            $("#Hs_Id").attr("disabled", "disabled");
            if (checkId.length == 0) {
                layer.msg("请选择要修改的房屋！");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一行信息修改！");
                return;
            }           
            SelectBuildingName();          
            GetUimName(Bd_Id);
            GetBdGround(Bd_Id);
            $("#Bd_Id").val(Bd_Id);
            $("#Hs_Id").val(checkId[0]);
            $("#Hs_Number").val(Hs_Number);
            $("#Uf_Id").val(Uf_Id);
            $("#Hs_InFloor").val(Hs_InFloor);
            $("#NatPer_Name").val(NatPer_Name);
            $("#NatPer_IDNumber").val(NatPer_IDNumber);
            $("#NatPer_Phone").val(NatPer_Phone);
            $("#NatPer_Sex").val(NatPer_Sex);
            $("#Hs_Proportion").val(Hs_Proportion);
            $("#Hs_Nature").val(Hs_Nature);
            $("#Hs_attribute").val(Hs_attribute);
            $("#Hs_HousUse").val(Hs_HousUse);
            $("#Hs_household").val(Hs_household);
            $("#Hs_Cqsx").val(Hs_Cqsx);
            $("#NatPer_Id").val(NatPer_Id);
            LayerOpen('800px', '450px', '房屋修改', $('#myModal'));


        })
    })


    /**
    * 房屋详情
    */
    $(function () {
        $("#btnMessage").click(function () {

            var checkId = CheckboxValueIDs();
            var Hs_Number = getTableCell(4);    //获取选中行的房号
            var Uf_Id = getTableCell(3);    //获取选中行的单元ID
            var Hs_InFloor = getTableCell(5);    //获取选中行的地上层数
            var NatPer_Name = getTableCell(6);    //获取选中行的业主姓名
            var NatPer_IDNumber = getTableCell(7);    //获取选中行的业主身份证号
            var NatPer_Phone = getTableCell(8);    //获取选中行的业主电话
            var NatPer_Sex = getTableCell(9);    //获取选中行的业主性别
            var Hs_Proportion = getTableCell(10);    //获取选中行的房屋面积
            var Hs_Nature = getTableCell(11);    //获取选中行的房屋性质
            var Hs_attribute = getTableCell(12);    //获取选中行的房屋属性
            var Hs_HousUse = getTableCell(13);    //获取选中行的房屋用途
            var Hs_household = getTableCell(14);    //获取选中行的本层第几户
            var Hs_Cqsx = getTableCell(15);         //获取选中行的产权属性
            if (checkId.length == 0) {
                layer.msg("请选择要查看的房屋！");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一行信息查看！");
                return;
            }            
            LayerOpen('800px', '380px', '房屋详情', $('#myModalMessage'));
            $("#Hs_Number1").html(Hs_Number);
            $("#Uim_Name").html(Uf_Id);
            $("#Hs_InFloor1").html(Hs_InFloor);
            $("#NatPer_Name1").html(NatPer_Name);
            $("#NatPer_IDNumber1").html(NatPer_IDNumber);
            $("#NatPer_Phone1").html(NatPer_Phone);
            $("#NatSex").html(NatPer_Sex);
            $("#Hs_Proportion1").html(Hs_Proportion);
            $("#Nature").html(Hs_Nature);
            $("#Attribute").html(Hs_attribute);
            $("#HousUse").html(Hs_HousUse);
            $("#Hs_household1").html(Hs_household);
            $("#Cqsx").html(Hs_Cqsx);
        })
    })


    /**
    * 删除房屋
    */
    $(function () {
        $("#btnDelete").click(function () {
            var checkId = CheckboxValueIDs();
            if (checkId.length == 0) {
                layer.msg("请选择要删除的楼宇！");                                                             //未选中任何行
                return;
            }
            else {
                layer.confirm("确定要删除吗?", { icon: 2, btn: ['确定', '取消'] }, function () {
                    ZorPostSimpleData("/Base/DeleteHousing", JSON.stringify({ 'id': checkId }), function (data) { //获取数据(带参数)
                        if (data.AnswerType == 1)
                            Replace();
                        layer.msg(data.AnswerMeg);
                    })
                })
            }
        })
    })

    /**
    * 刷新
    **/
    $(function () {
        $("#btnReplace").click(function () {
            Replace();
        })
    })

    /**
    * 保存
    */
    $(function () {
        $("#btnSure").click(function () {

            var value = $('#Bd_Id').val();
            if (value == '0') {
                layer.msg("请选择楼宇！");
                return;

            }
            var ufid = $('#Uf_Id').val();
            if (ufid == '0') {
                layer.msg("请选择单元！");
                return;

            }
            var infloor = $('#Hs_InFloor').val();
            if (infloor == '0') {
                layer.msg("请选择所在楼层！");
                return;

            }
            
            if (!CheckDataValid('.form-horizontal')) {
                return false;
            }
            var JsData = GetWebControls(divfrom);            
            ZorPostSimpleData("/Base/AddHousing", JSON.stringify({ "housing": JsData, "naturalPerson": JsData }), function (data) {
                layer.msg(data.AnswerMeg, function () {
                    layer.closeAll();
                    Replace();
                });
            });
        })
    })

    /**
    * 全选
    */
    $(function () {
        $("#cbkCheckAll").click(function () {
            if (this.checked) {
                $("input[name='chk']").prop('checked', true);
            } else {
                $("input[name='chk']").prop('checked', false);
            }
        })
    })


    /*导出*/
    $("#btnExport").click(function () {
        layer.open({
            type: 1,
            title: '导出提示',
            shade: false,
            skin: 'layui-layer-rim',
            area: ['620px', '280px'], //宽高
            content: $('#exportHtml')
        });
    });
    /*导出交互*/
    $("#btnExportSure").click(function () {
        var arr = new Array();
        $("[name='chk_list']").each(function () {
            if ($(this).is(":checked")) {
                arr.push($(this).attr("id") + "|" + $(this).val());
            }
        });
        $("#HousingMeg").val(arr);
        document.getElementById('formDownload').submit();
        layer.closeAll();
    });

</script>


